
$(function(){
    var iNow=0;
    $('.int-td-pro').click(function(){
        var iNow=$(this).index();
        tab(iNow);
    });
    function tab(iNow){
        $('.int-td-pro').css('opacity','0');
        $('.int-td-pro').eq(iNow).css('opacity','1');
    }
    var time=setInterval(function(){
        iNow++;
        if(iNow>$('.int-td-pro').length-1){
            iNow=0;
        }
        tab(iNow);
    },5000);
})
/**
 * 数据量比重
 *drawTodayPieTest--测试效果
 *drawTodayPie--请求获取数据
 */
cqrbdp.drawTodayPieTest = function() {
    var myChart = echarts.init(document.getElementById('piemain'));

    // 指定图表的配置项和数据
    var option = {
        color: ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'], //全局调色盘
        tooltip: {
            show: false,
            showContent: false,
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            show: false,
            orient: 'horizontal',
            left: 'center',
            bottom: 0,
            selectedMode: false,
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        },
        series: [{
            name: '访问来源',
            type: 'pie',
            itemStyle: {
                normal: {
                    color: function(obj) {
                        return option.color[obj.dataIndex];
                    },
                    label: {
                        show: false,
                    },
                    labelLine: {
                        show: false,
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}\n{c} ({d}%)',
                        textStyle: {
                            fontSize: '25',
                            fontWeight: 'bold'
                        }

                    }
                }
            },
            radius: ['88%', '79%'],
            data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    var pietitle = $("#pietitle");
    //echarts 2.0
    myChart.on(echarts.config.EVENT.HOVER, function() {
        pietitle.css("display", "none");
    });
    myChart.on(echarts.config.EVENT.MOUSEOUT, function() {
        pietitle.css("display", "block");
    });
    //echarts 3.0
    /*myChart.on('mouseover', function() {
        pietitle.css("display", "none");
    });
    myChart.on("mouseout", function() {
        pietitle.css("display", "block");
    });*/
    setInterval(function() {
        var jsonData = [{
            value: 502386291+parseInt(Math.random()*6123),
            name: '新浪新闻'
        }, {
            value: 7440000+parseInt(Math.random()*287),
            name: '腾讯微博'
        }, {
            value:  236837506+parseInt(Math.random()*4303),
            name: '微信公众号'
        }, {
            value: 242975+parseInt(Math.random()*1),
            name: '新闻客户端'
        }, {
            value: 272983053+parseInt(Math.random()*0.5),
            name: '音视频'
        },
        {
            value: 134690+parseInt(Math.random()*149),
            name: '境外新闻'
        },
        {
            value:193012810+parseInt(Math.random()*2),
            name: '国内新闻'
        },
        {
            value: 33845140+parseInt(Math.random()*22),
            name: '国内博客'
        },
        {
            value:  22874347+parseInt(Math.random()*339),
            name: '国内论坛'
        }];
        var series = myChart.getSeries();
        series[0].data = jsonData;
        myChart.setSeries(series, 'notMerge');

        cqrbdp.updatePieLegend(jsonData);
    }, 1000);
};

cqrbdp.drawTodayPie = function() {
    var myChart = echarts.init(document.getElementById('piemain'));

    // 指定图表的配置项和数据
    var option = {
        color: ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'], //全局调色盘
        tooltip: {
            show: false,
            showContent: false,
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            show: false,
            orient: 'horizontal',
            left: 'center',
            bottom: 0,
            selectedMode: false,
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        },
        series: [{
            name: '访问来源',
            type: 'pie',
            itemStyle: {
                normal: {
                    color: function(obj) {
                        return option.color[obj.dataIndex];
                    },
                    label: {
                        show: false,
                    },
                    labelLine: {
                        show: false,
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}\n{c} ({d}%)',
                        textStyle: {
                            fontSize: '25',
                            fontWeight: 'bold'
                        }

                    }
                }
            },
            radius: ['88%', '79%'],
           data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

    var pietitle = $("#pietitle");
    myChart.on(echarts.config.EVENT.HOVER, function() {
        pietitle.css("display", "none");
    });
    myChart.on(echarts.config.EVENT.MOUSEOUT, function() {
        pietitle.css("display", "block");
    });
    //请求获得数据，成功后更新统计图
    $.get('url', 'data', function(json) {
        var rawData = json.result; //查询返回的数据
        // var rawData = [
        //     { "class": "新闻", "number": "335" },
        //     { "class": "论坛", "number": "310" },
        //     { "class": "微信", "number": "234" },
        //     { "class": "新浪微博", "number": "135" },
        //     { "class": "腾讯微博", "number": "1548" }
        // ];
        var optionData = getOptionDataByRaw(rawData); //设置统计图options内的数据

        var series = myChart.getSeries();
        series[0].data = optionData;
        myChart.setSeries(series, 'notMerge');

        cqrbdp.updatePieLegend(optionData);
    });
    //格式化数据需要按照新闻、论坛、微信、新浪、腾讯的顺序
    function getOptionDataByRaw(rawData) {
        var result = [{
            name: '新浪微博'
        }, {
            name: '腾讯微博'
        }, {
            name: '微信公众号'
        }, {
            name: '新闻客户端'
        }, {
            name: '音视频'
        },
        {
            name: '境外新闻'
        },
        {
            name: '国内新闻'
        },
        {
            name: '国内博客'
        },
        {
            name: '国内论坛'
        }];
        var tempData = {};
        for (var i = 0; i < rawData.length; i++) {
            tempData[rawData[i].class] = rawData[i].number;
        }
        for (var i = 0; i < result.length; i++) {
            result[i].value = tempData[result[i].name];
        }
        return result;
    }
};


//根据数据计算出占比
cqrbdp.updatePieLegend = function(jsonData) {
    // var data = [335, 310, 234, 135, 1548];
    var total = 0;
    for (var i = 0; i < jsonData.length; i++) {
        total += parseInt(jsonData[i].value);
    }
    var newsProportion = Math.round((jsonData[0].value / total) * 100);
    var newsProportion2 = Math.round((jsonData[1].value / total) * 100);
    var newsProportion3 = Math.round((jsonData[2].value / total) * 100);
    var newsProportion4 = Math.round((jsonData[3].value / total) * 100);
    var newsProportion5 = Math.round((jsonData[4].value / total) * 100);

    var forumProportion = Math.round((jsonData[5].value / total) * 100);
    var wechatProportion = Math.round((jsonData[6].value / total) * 100);
    var xinlangProportion = Math.round((jsonData[7].value / total) * 100);
    var tencentProportion = Math.round((jsonData[8].value / total) * 100);
    $("#newLegend .legend-data").html(newsProportion + "%");
    $("#newLegend2 .legend-data").html(newsProportion2 + "%");
    $("#newLegend3 .legend-data").html(newsProportion3 + "%");
    $("#newLegend4 .legend-data").html(newsProportion4 + "%");
    $("#newLegend5 .legend-data").html(newsProportion5 + "%");

    $("#forumLegend .legend-data").html(forumProportion + "%");
    $("#wechatLegend .legend-data").html(wechatProportion + "%");
    $("#xinlangLegend .legend-data").html(xinlangProportion + "%");
    $("#tencentLegend .legend-data").html(tencentProportion + "%");
}



cqrbdp.drawTodayPieTest1 = function() {
    var myChart1 = echarts.init(document.getElementById('piemain1'));

    // 指定图表的配置项和数据
    var option11 = {
        color: ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'], //全局调色盘
        tooltip: {
            show: false,
            showContent: false,
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            show: false,
            orient: 'horizontal',
            left: 'center',
            bottom: 0,
            selectedMode: false,
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        },
        series: [{
            name: '访问来源',
            type: 'pie',
            itemStyle: {
                normal: {
                    color: function(obj) {
                        return option11.color[obj.dataIndex];
                    },
                    label: {
                        show: false,
                    },
                    labelLine: {
                        show: false,
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}\n{c} ({d}%)',
                        textStyle: {
                            fontSize: '25',
                            fontWeight: 'bold'
                        }

                    }
                }
            },
            radius: ['88%', '79%'],
            data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart1.setOption(option11);
    var pietitle1 = $("#pietitle1");
    //echarts 2.0
    myChart1.on(echarts.config.EVENT.HOVER, function() {
        pietitle1.css("display", "none");
    });
    myChart1.on(echarts.config.EVENT.MOUSEOUT, function() {
        pietitle1.css("display", "block");
    });
    //echarts 3.0
    /*myChart.on('mouseover', function() {
        pietitle.css("display", "none");
    });
    myChart.on("mouseout", function() {
        pietitle.css("display", "block");
    });*/
    setInterval(function() {
        var jsonData1 = [{
            value: 3516704037+parseInt(Math.random()*61231),
            name: '新浪新闻'
        }, {
            value: 52080000+parseInt(Math.random()*2871),
            name: '腾讯微博'
        }, {
            value:  236837506+parseInt(Math.random()*43031),
            name: '微信公众号'
        }, {
            value: 1657862542+parseInt(Math.random()*11),
            name: '新闻客户端'
        }, {
            value: 1910881371+parseInt(Math.random()*5),
            name: '音视频'
        },
        {
            value: 942830+parseInt(Math.random()*1491),
            name: '境外新闻'
        },
        {
            value:1351089670+parseInt(Math.random()*21),
            name: '国内新闻'
        },
        {
            value: 236915980+parseInt(Math.random()*221),
            name: '国内博客'
        },
        {
            value:  160120429+parseInt(Math.random()*3391),
            name: '国内论坛'
        }];
        var series1 = myChart1.getSeries();
        series1[0].data = jsonData1;
        myChart1.setSeries(series1, 'notMerge');

        cqrbdp.updatePieLegend1(jsonData1);
    }, 1000);
};

cqrbdp.drawTodayPie1 = function() {
    var myChart1 = echarts.init(document.getElementById('piemain1'));

    // 指定图表的配置项和数据
    var option11 = {
        color: ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'], //全局调色盘
        tooltip: {
            show: false,
            showContent: false,
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            show: false,
            orient: 'horizontal',
            left: 'center',
            bottom: 0,
            selectedMode: false,
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        },
        series: [{
            name: '访问来源',
            type: 'pie',
            itemStyle: {
                normal: {
                    color: function(obj) {
                        return option11.color[obj.dataIndex];
                    },
                    label: {
                        show: false,
                    },
                    labelLine: {
                        show: false,
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}\n{c} ({d}%)',
                        textStyle: {
                            fontSize: '25',
                            fontWeight: 'bold'
                        }

                    }
                }
            },
            radius: ['88%', '79%'],
           data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart1.setOption(option11);

    var pietitle1 = $("#pietitle1");
    myChart1.on(echarts.config.EVENT.HOVER, function() {
        pietitle1.css("display", "none");
    });
    myChart1.on(echarts.config.EVENT.MOUSEOUT, function() {
        pietitle1.css("display", "block");
    });
    //请求获得数据，成功后更新统计图
    $.get('url', 'data', function(json) {
        var rawData1 = json.result; //查询返回的数据
        var optionData1 = getOptionDataByRaw1(rawData1); //设置统计图options内的数据

        var series1 = myChart1.getSeries();
        series1[0].data = optionData1;
        myChart1.setSeries(series1, 'notMerge');

        cqrbdp.updatePieLegend1(optionData1);
    });
    //格式化数据需要按照新闻、论坛、微信、新浪、腾讯的顺序
    function getOptionDataByRaw1(rawData1) {
        var result1 = [{
            name: '新浪微博'
        }, {
            name: '腾讯微博'
        }, {
            name: '微信公众号'
        }, {
            name: '新闻客户端'
        }, {
            name: '音视频'
        },
        {
            name: '境外新闻'
        },
        {
            name: '国内新闻'
        },
        {
            name: '国内博客'
        },
        {
            name: '国内论坛'
        }];
        var tempData1 = {};
        for (var i = 0; i < rawData1.length; i++) {
            tempData1[rawData1[i].class] = rawData1[i].number;
        }
        for (var i = 0; i < result1.length; i++) {
            result1[i].value = tempData1[result1[i].name];
        }
        return result1;
    }
};


//根据数据计算出占比
cqrbdp.updatePieLegend1 = function(jsonData1) {
    // var data = [335, 310, 234, 135, 1548];
    var total = 0;
    for (var i = 0; i < jsonData1.length; i++) {
        total += parseInt(jsonData1[i].value);
    }
    var newsProportion = Math.round((jsonData1[0].value / total) * 100);
    var newsProportion2 = Math.round((jsonData1[1].value / total) * 100);
    var newsProportion3 = Math.round((jsonData1[2].value / total) * 100);
    var newsProportion4 = Math.round((jsonData1[3].value / total) * 100);
    var newsProportion5 = Math.round((jsonData1[4].value / total) * 100);

    var forumProportion = Math.round((jsonData1[5].value / total) * 100);
    var wechatProportion = Math.round((jsonData1[6].value / total) * 100);
    var xinlangProportion = Math.round((jsonData1[7].value / total) * 100);
    var tencentProportion = Math.round((jsonData1[8].value / total) * 100);
    $("#newLegend .legend-data").html(newsProportion + "%");
    $("#newLegend2 .legend-data").html(newsProportion2 + "%");
    $("#newLegend3 .legend-data").html(newsProportion3 + "%");
    $("#newLegend4 .legend-data").html(newsProportion4 + "%");
    $("#newLegend5 .legend-data").html(newsProportion5 + "%");

    $("#forumLegend .legend-data").html(forumProportion + "%");
    $("#wechatLegend .legend-data").html(wechatProportion + "%");
    $("#xinlangLegend .legend-data").html(xinlangProportion + "%");
    $("#tencentLegend .legend-data").html(tencentProportion + "%");
}
// 本月数据量比重
cqrbdp.drawTodayPieTest2 = function() {
    var myChart2 = echarts.init(document.getElementById('piemain2'));

    // 指定图表的配置项和数据
    var option22 = {
        color: ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'], //全局调色盘
        tooltip: {
            show: false,
            showContent: false,
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            show: false,
            orient: 'horizontal',
            left: 'center',
            bottom: 0,
            selectedMode: false,
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        },
        series: [{
            name: '访问来源',
            type: 'pie',
            itemStyle: {
                normal: {
                    color: function(obj) {
                        return option22.color[obj.dataIndex];
                    },
                    label: {
                        show: false,
                    },
                    labelLine: {
                        show: false,
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}\n{c} ({d}%)',
                        textStyle: {
                            fontSize: '25',
                            fontWeight: 'bold'
                        }

                    }
                }
            },
            radius: ['88%', '79%'],
            data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart2.setOption(option22);
    var pietitle2 = $("#pietitle2");
    //echarts 2.0
    myChart2.on(echarts.config.EVENT.HOVER, function() {
        pietitle2.css("display", "none");
    });
    myChart2.on(echarts.config.EVENT.MOUSEOUT, function() {
        pietitle2.css("display", "block");
    });
    setInterval(function() {
        var jsonData2 = [{
            value: 15071588730+parseInt(Math.random()*612300),
            name: '新浪新闻'
        }, {
            value: 223200000+parseInt(Math.random()*28700),
            name: '腾讯微博'
        }, {
            value:  7105125180+parseInt(Math.random()*430300),
            name: '微信公众号'
        }, {
            value: 7289250+parseInt(Math.random()*100),
            name: '新闻客户端'
        }, {
            value: 8189491590+parseInt(Math.random()*50),
            name: '音视频'
        },
        {
            value: 4040700+parseInt(Math.random()*14900),
            name: '境外新闻'
        },
        {
            value:5790384300+parseInt(Math.random()*200),
            name: '国内新闻'
        },
        {
            value: 101535420+parseInt(Math.random()*2200),
            name: '国内博客'
        },
        {
            value:  686230410+parseInt(Math.random()*33900),
            name: '国内论坛'
        }];
        var series2 = myChart2.getSeries();
        series2[0].data = jsonData2;
        myChart2.setSeries(series2, 'notMerge');

        cqrbdp.updatePieLegend2(jsonData2);
    }, 1000);
};

cqrbdp.drawTodayPie2 = function() {
    var myChart2 = echarts.init(document.getElementById('piemain2'));

    // 指定图表的配置项和数据
    var option11 = {
        color: ['#70d9ff', '#e76258', '#4CE73C', '#1793fd', '#F2d703','#ff954d','#583ab5','#73fff1','#978ece'], //全局调色盘
        tooltip: {
            show: false,
            showContent: false,
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            show: false,
            orient: 'horizontal',
            left: 'center',
            bottom: 0,
            selectedMode: false,
            data: ['新浪微博', '腾讯微博', '微信公众号', '新闻客户端', '音视频','境外新闻','国内新闻','国内博客','国内论坛']
        },
        series: [{
            name: '访问来源',
            type: 'pie',
            itemStyle: {
                normal: {
                    color: function(obj) {
                        return option22.color[obj.dataIndex];
                    },
                    label: {
                        show: false,
                    },
                    labelLine: {
                        show: false,
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}\n{c} ({d}%)',
                        textStyle: {
                            fontSize: '25',
                            fontWeight: 'bold'
                        }

                    }
                }
            },
            radius: ['88%', '79%'],
           data: [502386291, 7440000, 236837506,242975, 272983053,134690, 193012810,33845140,22874347],
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart2.setOption(option22);

    var pietitle2= $("#pietitle2");
    myChart2.on(echarts.config.EVENT.HOVER, function() {
        pietitle2.css("display", "none");
    });
    myChart2.on(echarts.config.EVENT.MOUSEOUT, function() {
        pietitle2.css("display", "block");
    });
    //请求获得数据，成功后更新统计图
    $.get('url', 'data', function(json) {
        var rawData2 = json.result; //查询返回的数据
        var optionData2 = getOptionDataByRaw2(rawData2); //设置统计图options内的数据

        var series2 = myChart2.getSeries();
        series2[0].data = optionData2;
        myChart2.setSeries(series2, 'notMerge');

        cqrbdp.updatePieLegend2(optionData2);
    });
    //格式化数据需要按照新闻、论坛、微信、新浪、腾讯的顺序
    function getOptionDataByRaw2(rawData1) {
        var result2 = [{
            name: '新浪微博'
        }, {
            name: '腾讯微博'
        }, {
            name: '微信公众号'
        }, {
            name: '新闻客户端'
        }, {
            name: '音视频'
        },
        {
            name: '境外新闻'
        },
        {
            name: '国内新闻'
        },
        {
            name: '国内博客'
        },
        {
            name: '国内论坛'
        }];
        var tempData2 = {};
        for (var i = 0; i < rawData2.length; i++) {
            tempData2[rawData2[i].class] = rawData2[i].number;
        }
        for (var i = 0; i < result2.length; i++) {
            result2[i].value = tempData2[result1[i].name];
        }
        return result1;
    }
};


//根据数据计算出占比
cqrbdp.updatePieLegend2 = function(jsonData2) {
    // var data = [335, 310, 234, 135, 1548];
    var total = 0;
    for (var i = 0; i < jsonData2.length; i++) {
        total += parseInt(jsonData2[i].value);
    }
    var newsProportion = Math.round((jsonData2[0].value / total) * 100);
    var newsProportion2 = Math.round((jsonData2[1].value / total) * 100);
    var newsProportion3 = Math.round((jsonData2[2].value / total) * 100);
    var newsProportion4 = Math.round((jsonData2[3].value / total) * 100);
    var newsProportion5 = Math.round((jsonData2[4].value / total) * 100);

    var forumProportion = Math.round((jsonData2[5].value / total) * 100);
    var wechatProportion = Math.round((jsonData2[6].value / total) * 100);
    var xinlangProportion = Math.round((jsonData2[7].value / total) * 100);
    var tencentProportion = Math.round((jsonData2[8].value / total) * 100);
    $("#newLegend .legend-data").html(newsProportion + "%");
    $("#newLegend2 .legend-data").html(newsProportion2 + "%");
    $("#newLegend3 .legend-data").html(newsProportion3 + "%");
    $("#newLegend4 .legend-data").html(newsProportion4 + "%");
    $("#newLegend5 .legend-data").html(newsProportion5 + "%");

    $("#forumLegend .legend-data").html(forumProportion + "%");
    $("#wechatLegend .legend-data").html(wechatProportion + "%");
    $("#xinlangLegend .legend-data").html(xinlangProportion + "%");
    $("#tencentLegend .legend-data").html(tencentProportion + "%");
}